//
//  AbountVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/29.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "AbountVC.h"
#import "SYRequestAPI+Wode.h"
#import "JianChaGengXInModel.h"

@interface AbountVC ()
{
    NSArray *arraySection;
}
@end

@implementation AbountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    arraySection = @[@"当前版本",@"隐私条款",@"意见反馈"];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.navView];
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@50);
    }];
    [self.view addSubview:self.tableList];
    [_tableList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.equalTo(@549);
        make.top.equalTo(self->_navView.mas_bottom).offset(269);
        make.bottom.equalTo(@0);
    }];
    [self.view addSubview:self.topImageView];
    [_topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.view.mas_top).offset(135);
        make.width.equalTo(@182);
        make.height.equalTo(@70);
    }];
    
}
- (WoDeNavView *)navView{
    if (!_navView) {
        WoDeNavView *topView = [[WoDeNavView alloc]init];
        topView.frame = CGRectMake(0, 0, self.view.frame.size.width,50);
        topView.titleLabel.text = @"关于我们";
        topView.editeButton.hidden = YES;
        _navView = topView;
    }
    return _navView;
}
- (UIImageView *)topImageView{
    if (!_topImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"wode_logo"];
        _topImageView = imageView;
    }
    return _topImageView;
}
- (UITableView *)tableList{
    if (!_tableList) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 144, self.view.frame.size.width-200, APP_HEIGHT-84) style:UITableViewStylePlain];
        tableView.delegate  =self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor whiteColor];
        [tableView registerClass:[AbountOurCell class] forCellReuseIdentifier:@"AbountOurCell"];
        tableView.scrollEnabled = NO;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableList = tableView;
    }
    return _tableList;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
        return 2;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 21;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AbountOurCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AbountOurCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[AbountOurCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AbountOurCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.section == 0) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.leftLabel.text = arraySection[0];
        //获取app版本号
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        cell.rightLabel.text = app_Version;
        [cell addLine];
    }else{
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.leftLabel.text = arraySection[indexPath.row+1];
        if (indexPath.row == 0) {
//            cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1121556524499"]];
        }else{
//            cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1131556524500"]];
        }
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了cell");
    if (indexPath.section == 0) {
        //检查跟新
        [self getJianChaGengXinRequest];
    }else{
        if (indexPath.row == 0) {
            _privacyTreatyView = [[PrivacyTreatyView alloc]initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
            [self.view addSubview:self.privacyTreatyView];
            [UIView animateWithDuration:0.5 animations:^{
                self->_privacyTreatyView.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            }];
        }else{
            _fadBackViewView = [[FadBackView alloc]initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
            [self.view addSubview:self.fadBackViewView];
            [UIView animateWithDuration:0.5 animations:^{
                self->_fadBackViewView.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            }];
        }
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    return view;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, self.view.frame.size.width, 21);
    return view;
}
#pragma mark - 检查更新
- (void)getJianChaGengXinRequest{
    [MBProgressHUD mj_showMessage:nil toView:self.view];
    [SYRequestAPI sy_getSafeServiceCheckUpdate:@{} success:^(id  _Nonnull responseObject) {
        NSLog(@"得到检查更新的数据 %@",responseObject);
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSString *code = [USERDEFAL objectForKey:@"VersionCodeDefalut"];
        JianChaGengXInModel *model = [JianChaGengXInModel yy_modelWithJSON:dic];
        if (code == model.versionCode) {
            
        }else{
           [USERDEFAL setObject:model.versionCode forKey:VersionCodeDefalut];
        }
        [MBProgressHUD mj_hideHUDForView:self.view];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
